package com.buaa.util.etl;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import com.buaa.util.FilterUtils;
import com.buaa.util.SymbolUtils;

public class ResourceUtils {

	// 单位名称(1)
	public static String getUnit_name(String unit_name) {
		if (unit_name == null || unit_name.equals(""))
			return "";
		// return null;
		Set<Character> symbol = new HashSet<Character>();
		SymbolUtils.addZhSym(symbol);
		symbol.add('(');
		symbol.add(')');
		return FilterUtils.characterFilter(unit_name, symbol, "", 0);
	}

	// 单位编码(2)
	public static Long getUnit_code(String unit_code) {
		if (unit_code == null || unit_code.equals(""))
			return -1L;
		String regEx = "^\\d{13}$";
		return FilterUtils.longPatternFilter(unit_code, regEx, 0);
	}

	// 项目名称/资源名称(3)-- 冗余
	// 产品/产品类别(4)
	public static String getType(String type) {
		if (type == null || type.equals(""))
			return "";
		type = type.trim().replace("	", "").replace("　", " ").replace("—", "-").replace("－", "-").replace("–", "-")
				.replace("○", "〇").replace("′", "’").trim();
		Set<Character> symbol = new HashSet<Character>();
		SymbolUtils.addAllSym(symbol);
		return FilterUtils.characterFilter(type, symbol, "", 5);
	}

	// 限制范围_备注(5)
	public static String getBound(String bound) {
		if (bound == null || bound.equals(""))
			return "";
		bound = bound.trim();
		Set<Character> symbol = new HashSet<Character>();
		SymbolUtils.addZhSym(symbol);
		SymbolUtils.addEnSym(symbol);
		SymbolUtils.addArabicSym(symbol);
		SymbolUtils.addOtherDigitSym(symbol);
		SymbolUtils.addOtherSym(symbol);
		return FilterUtils.characterFilter(bound, symbol, "", 4);
	}

	// 产业(6)
	public static String getIndustry1(String industry1) {
		if (industry1 == null || industry1.equals(""))
			return "";
		industry1 = industry1.replace("/", ",");
		String regEx = "^[\u4E00-\u9FA5]+(,[\u4E00-\u9FA5]+)*$";
		return FilterUtils.patternFilter(industry1, regEx, "");
	}

	// 检测领域(父)(7)
	public static String getDf_parent(String df_parent) {
		if (df_parent == null || df_parent.equals(""))
			return "";
		Set<Character> symbol = new HashSet<Character>();
		SymbolUtils.addArabicSym(symbol);
		return FilterUtils.characterFilter(df_parent, symbol, "", 4);
	}

	// 行业类别（父）(8)
	public static String getIc_parent(String ic_parent) {
		if (ic_parent == null || ic_parent.equals(""))
			return "";
		return FilterUtils.characterFilter(ic_parent, null, "", 0);
	}

	// 黑龙江产业(9)
	public static String getIndustry2(String industry2) {
		if (industry2 == null || industry2.equals(""))
			return "";
		String regEx = "^[\u4E00-\u9FA5]+(,[\u4E00-\u9FA5]+)*$";
		return FilterUtils.patternFilter(industry2, regEx, "");
	}

	// 检测价格(10)
	public static Integer getDetection_price(String detection_price) {
		if (detection_price == null || detection_price.equals(""))
			return -1;
		return FilterUtils.integerFilter(detection_price);
	}

	// 检测标准(11)
	public static String getDetection_criterion(String detection_criterion) {
		if (detection_criterion == null || detection_criterion.equals(""))
			return "";
		detection_criterion = detection_criterion.replace("—", "-").replace("－", "-").replace("–", "-")
				.replace("	", " ").replace("○", "〇").replace("′", "’");
		Set<Character> symbol = new HashSet<Character>();
		SymbolUtils.addAllSym(symbol);
		return FilterUtils.characterFilter(detection_criterion, symbol, "", 5);
	}

	// 检测周期(12)
	public static String getDetection_period(String detection_period) {
		if (detection_period == null || detection_period.equals(""))
			return "";
		detection_period = detection_period.trim().replace("天", "").replace("无", "0");
		String regEx = "^\\d+$";
		return FilterUtils.patternFilter(detection_period, regEx, "");
	}

	// 服务图片(13)
	public static String getPic(String pic) {
		if (pic == null || pic.equals(""))
			return "";
		String[] suffixes = { ".jpg", ".JPG", ".jpeg", ".gif" };
		return FilterUtils.fileFilter(pic, suffixes);
	}

	// 委托书 (14)
	public static String getProxy(String proxy) {
		if (proxy == null || proxy.equals(""))
			return "";
		String[] suffixes = { ".doc", ".docx" };
		return FilterUtils.fileFilter(proxy, suffixes);
	}

	// 新增时间 (15)
	public static Date getCreate_time(String create_time) throws ParseException {
		if (create_time == null || create_time.equals(""))
			return new SimpleDateFormat("yyyy-MM-dd").parse("1000-01-01");
		// return null;
		return FilterUtils.dateFilter(create_time, "yyyy/MM/dd HH:mm:ss");
	}

	// 修改时间 (16)
	public static Date getUpdate_time(String update_time) throws ParseException {
		if (update_time == null || update_time.equals(""))
			return new SimpleDateFormat("yyyy-MM-dd").parse("1000-01-01");
		return FilterUtils.dateFilter(update_time, "yyyy/MM/dd HH:mm");
	}

	// 联系人(17)
	public static String getContact_person(String contact_person) {
		if (contact_person == null || contact_person.equals(""))
			return "";
		contact_person = contact_person.replace(" ", "").replace("·", "");
		HashSet<Character> symbol = new HashSet<Character>();
		symbol.add('、');
		return FilterUtils.characterFilter(contact_person, symbol, "", 4);
	}

	// 联系人电话(18)
	public static String getContact_phone(String contact_phone) {
		if (contact_phone == null || contact_phone.equals(""))
			return "";
		switch (contact_phone) {
		case "13946847237食品类":
			contact_phone = "13946847237";
			break;
		case "（010）5829-2800转2862":
			contact_phone = "010-58292800-2862";
		case "13836130668q":
			contact_phone = "13836130668";
		default:
			break;
		}
		contact_phone = contact_phone.trim().replace("－", "-").replace("—", "-").replace("_", "-").replace("--", "-")
				.replace("转", "-").replace("   ", "/").replace("  ", "/").replace("、", "/").replace(" ", "-");
		return FilterUtils.phoneFilter(contact_phone, "");
	}

	// 联系人传真(19)
	public static String getContact_fax(String contact_fax) {
		if (contact_fax == null || contact_fax.equals(""))
			return "";
		if (contact_fax.equals("（010）5829-2828"))
			contact_fax = "010-58292828";
		contact_fax = contact_fax.replace("－", "-").replace("—", "-").replace("--", "-");
		return FilterUtils.faxFilter(contact_fax);
	}

	// 联系人邮箱(20)
	public static String getContact_email(String contact_email) {
		if (contact_email == null || contact_email.equals(""))
			return "";
		contact_email = contact_email.replace("  ", ",").replace("？", "");
		return FilterUtils.emailFilter(contact_email);
	}

	// 产品/产品类别(21)-- 冗余
	// 单位地址(22)
	public static String getUnit_addr(String unit_addr) {
		if (unit_addr == null || unit_addr.equals(""))
			return "";
		unit_addr = unit_addr.replace(" ", "");
		Set<Character> symbol = new HashSet<Character>();
		SymbolUtils.addArabicSym(symbol);
		symbol.add('-');
		return FilterUtils.characterFilter(unit_addr, symbol, "", 4);
	}

	// 单位所在城市(23)
	public static String getUnit_city(String unit_city) {
		if (unit_city == null || unit_city.equals(""))
			return "";
		if(!unit_city.endsWith("大兴安岭地区 ")||!unit_city.endsWith("大兴安岭 ")){
			if(!unit_city.endsWith("市"))
				unit_city += "市";
		}
		return FilterUtils.characterFilter(unit_city, null, "", 0);
	}

	// 单位名称(24)--冗余
	// 检测领域(子)(25)
	public static String getDf_child(String df_child) {
		if (df_child == null || df_child.equals(""))
			return "";
		df_child = df_child.replace("—", "-");
		Set<Character> symbol = new HashSet<Character>();
		symbol.add('、');
		symbol.add(',');
		symbol.add('-');
		return FilterUtils.characterFilter(df_child, symbol, "", 0);
	}

	// 行业类别（子）(26)
	public static String getIc_child(String ic_child) {
		if (ic_child == null || ic_child.equals(""))
			return "";
		return FilterUtils.characterFilter(ic_child, null, "", 0);
	}

}
